import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

// 导入全局样式
import "./assets/css/global.css"

Vue.config.productionTip = false

// 配置axios
import axios from "./utils/request.js";
Vue.prototype.$axios = axios;

//配置element-ui
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

// 配置vant
import Vant from 'vant';
import 'vant/lib/index.css';
Vue.use(Vant);

// 配置echarts
import * as echarts from "echarts";
Vue.prototype.$echarts = echarts;


// 全局路由守卫
router.beforeEach((to, from, next) => {

	// 判断是否为后台管理也页面
	if (to.path.indexOf("/admin") > -1) {
		// 判断是否为登录页面
		if (to.path == "/admin/login") {
			// 判断当token值不为空时，跳转到管理后台首页
			if (store.state.token != "") {
				next("/admin/main")
			}
		} else {
			// 判断当token为空时，跳转到登录页面
			if (store.state.token == "") {
				next("/admin/login")
			}
		}
	}
	// 动态设置面包屑
	if (to.meta.hasOwnProperty("bread")) {
		store.commit("setBread", to.meta.bread);
	}

	next();
})

new Vue({
	router,
	store,
	render: h => h(App)
}).$mount('#app')
